package com.qf.zhijia.zhijiasearch.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author 岳鹏
 * @Date 2020/9/10
 */
@Configuration
public class ProductMQConfig {

    /**
     * 创建交换机
     */
    @Bean
    public TopicExchange productTopicExchange(){
        return ExchangeBuilder.topicExchange("product-es-exchange").durable(true).build();
    }

    /**
     * 创建队列
     */
    @Bean
    public Queue productQueue(){
        return QueueBuilder.durable("product-queue").build();
    }

    /**
     * 将队列绑定到交换机；并指定接收参数的路由类型
     */
    @Bean
    public Binding getBindign(@Qualifier("productTopicExchange") TopicExchange productTopicExchange,
                              @Qualifier("productQueue") Queue productQueue){
        return BindingBuilder.bind(productQueue).to(productTopicExchange).with("api.product.*");
    }

}
